package com.java.inventory.mapper;

import com.java.inventory.entity.Inventory;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * 库存表 Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2022-11-16
 */
public interface InventoryMapper extends BaseMapper<Inventory> {
    /**
     * 锁库存
     * @param id
     * @param needLockNum
     * @return
     */
    @Update("<script>update inventory set lock_num = lock_num + #{needLockNum},ava_num = ava_num - #{needLockNum},version = version + 1 where id = #{id} and ava_num - #{needLockNum}  >= 0</script>")
    int lockInventory(@Param("id") Long id,@Param("needLockNum") Long needLockNum);
}
